package com.wf.smartcomm.server.client.action;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.opensymphony.xwork2.ActionSupport;
import com.wf.smartcomm.server.model.Page;
import com.wf.smartcomm.server.util.StringUtil;

/** 
 * @author 38884306@qq.com  
 * @version 创建时间：2015-5-19 下午2:12:23 
 * 
 */
@Controller(value="clientBaseAction")
@Scope("prototype")
public class BaseAction extends ActionSupport implements ServletRequestAware,
ServletResponseAware{

	protected HttpServletRequest request;
	protected HttpServletResponse response;
	//protected HttpSession session;
	protected Page page = new Page();
	protected Gson gson = new GsonBuilder()
	.excludeFieldsWithoutExposeAnnotation().create();
	
	protected static Logger logger = Logger.getLogger(BaseAction.class);
	
	protected static String oauth_base_url_dev= "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxffc40119d6248ec7&secret=beec04439e911f41b8ada347164b2bd5";
	
	protected static String oauth_base_url_gen= "https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxe6bd1c8612e721c5&secret=6a1fe5fc0557e6baf92d01fb74d76dbb";
	
	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}

	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
		//session = request.getSession();
		String pageSize = request.getParameter("pageSize");
		String pageIndex = request.getParameter("pageIndex");
		if (!StringUtil.isEmpty(pageSize)) {
			page.setPageSize(Integer.parseInt(pageSize));
		}
		if (!StringUtil.isEmpty(pageIndex)) {
			page.setCurrentPage(Integer.parseInt(pageIndex));
		}
	}

	protected void printJsonData(Object json) throws IOException {
		response.setContentType("application/json;charset=UTF-8");
		PrintWriter out = response.getWriter();
		out.print(json);
		out.close();
	}
}
